package cn.xizikelif.org.controller;

import cn.xizikelif.basic.query.BaseQuery;
import cn.xizikelif.basic.util.AjaxResult;
import cn.xizikelif.basic.util.PageList;
import cn.xizikelif.org.domain.Systemdictionarydetail;
import cn.xizikelif.org.service.SystailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/syst")
@Api(value = "部门的API",description = "部门相关的CRUD功能")
public class SystailController {

    @Autowired
    private SystailService systailService;

    /*查询单个*/
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public Systemdictionarydetail findById(@ApiParam(value="主键id",readOnly = true) @PathVariable("id") long id){
        return systailService.findById(id);
    }
    @RequestMapping("/e/{id}")
    public List<Systemdictionarydetail> findByOne(@PathVariable("id") Long id) {
        return systailService.findByOne(id);
    }

/*    *//*查询一条*//*
    @GetMapping("/e/{id}")
    public List<Systemdictionarydetail> findByOne(@PathVariable("id") Long id){
        return systailService.findByOne(id);
    }*/

    /*查询全部*/
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return systailService.findAll();
    }

    /*添加和修改*/
    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        if(null != systemdictionarydetail.getId()){
            // 修改
            systailService.update(systemdictionarydetail);

        }else {
            // 添加
            systailService.add(systemdictionarydetail);
        }
        return AjaxResult.me().success();
    }

    /*删除*/
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") long id){
        systailService.delete(id);
        return AjaxResult.me().success();
    }

    /*分页查询*/
    @PostMapping
    public PageList<Systemdictionarydetail> queryByPage(@RequestBody BaseQuery query){
        return systailService.queryByPage(query);
    }

    /*批量删除*/
    @PatchMapping
    public AjaxResult bachDelete(@RequestBody List<Long> ids){
       systailService.bachDelete(ids);
        return AjaxResult.me().success();
    }

}
